home *** CD-ROM | disk | FTP | other *** search
- // Copyright (C) 1997-2002 Alias|Wavefront,
- // a division of Silicon Graphics Limited.
- //
- // The information in this file is provided for the exclusive use of the
- // licensees of Alias|Wavefront. Such users have the right to use, modify,
- // and incorporate this code into other products for purposes authorized
- // by the Alias|Wavefront license agreement, without fee.
- //
- // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
- // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
- // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
- // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
- // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
- // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
- // PERFORMANCE OF THIS SOFTWARE.
- //
- //
- // Alias|Wavefront Script File
- // MODIFY THIS AT YOUR OWN RISK
- //
- // Creation Date: 1 December 1996
- //<doc>
- //<name interToUI>
- //<owner "Alias|Wavefront Unsupported">
- //
- //<synopsis>
- // string interToUI(string $interCapName)
- //
- //<description>
- // Takes a string in interCaps form,
- // and returns a "UI" string. Allows
- // things that are called something like
- // graphEditor to be shown to the
- // user as "Graph Editor"
- //
- //<flags>
- // string $interCapName Name to convert, assumed to be in interCaps.
- //
- //<returns>
- // string : Converted name
- //
- //<examples>
- // interToUI( "graphEditor" );
- // // Result : Graph Editor //
- // interToUI( "heffalump" );
- // // Result : Heffalump //
- // interToUI( "AndWoozles" );
- // // Result : And Woozles //
- //
- //</doc>
- //
- global proc string interToUI( string $input )
- {
-
- string $retval = "";
- int $stringSize = size( $input );
-
- if (0 < $stringSize) {
- string $character = substring( $input, 1, 1 );
- string $upperChar = toupper( $character );
- $retval = ( $retval + $upperChar );
-
- int $parenLevel = 0;
- int $capitalizeNext = false;
- string $prevChar = $character;
-
- for( $i=2; $i <= $stringSize; $i++ ) {
- $character = substring( $input, $i, $i );
- $upperChar = toupper( $character );
-
- // Capitalize this character if the previous was a "."
- //
- if( $capitalizeNext ) {
- $character = $upperChar;
- }
-
- // Do not add spaces before numbers or brackets/parens
- // or else "myMultiAttr[16]" will come out as
- // "My Multi Attr [ 1 6 ]"
- //
- int $isOpenParen = size( match( "\\[", $character ) ) ||
- size( match( "\\(", $character ) );
- int $isCloseParen= size( match( "\\]", $character ) ) ||
- size( match( "\\)", $character ) );
-
- int $isPeriod = size( match( "\\.", $character ) );
-
- // Increment the level of nested parens
- //
- if( $isOpenParen ) {
- $parenLevel++;
- }
-
- // Take "." to mean a new phrase starts and we
- // need a capital letter.
- //
- if( $isPeriod ) {
- $capitalizeNext = true;
- }
-
- // If the character is already capitalized, then
- // insert a space before putting the character
- // back into the string
- //
- if( ($character==$upperChar) && !$isPeriod && ($parenLevel==0) )
- {
- // The only exception is if we're beginning a new
- // phrase. "T.Tx" should remain "T.Tx" not "T. Tx"
- //
- // Also, don't separate groups of caps.
- // "colorRGB" should appear as "Color RGB"
- // not "Color R G B".
- //
- if( !$capitalizeNext
- &&( $prevChar != toupper($prevChar) ) )
- {
- $retval = ( $retval + " " );
- }
- $capitalizeNext = false;
- }
-
- // Decrement the level of nested parens
- //
- if( $isCloseParen ) {
- $parenLevel--;
- }
-
- $retval = ( $retval + $character );
- $prevChar = $character;
- }
- }
- return $retval;
- }
-